Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.HtmlControls
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Xml.Linq
Imports System.Collections.Generic
Imports facebook.Utility
Imports System.Text
Imports System.Web.Configuration

Namespace FBMLSample
	Partial Public Class mysmiles
		Inherits BasePage
		Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As EventArgs)
			Me.Master.RequireLogin = True
			Master.SetSelectedTab("mysmiles")
		End Sub

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
			'TODO, Check Form POST to see if it is inside of a tab or not...
			Dim moodList As List(Of String) = JSONHelper.ConvertFromJSONArray(Me.Master.API.data.getUserPreference(0))

			lblMoodList.Text = buildMoodListFBML(moodList)
			If (Not String.IsNullOrEmpty(lblMoodList.Text)) Then
				announce.Text = String.Format("We are pleased to announce that <fb:name useyou=""false"" uid=""{0}""/> has been feeling:",Master.API.uid)
			Else
				announce.Text = String.Format("<fb:name useyou=""false"" uid=""{0}""/> has never told us their feelings.",Master.API.uid)
			End If

			lblLink.Text = "<a href=""http://apps.facebook.com/" & Master.suffix & """>Check out Smiley</a>"
		End Sub

		Private Function buildMoodListFBML(ByVal moodList As List(Of String)) As String
			Dim len As Integer = 3
			Dim fbml = New StringBuilder()
			Dim moods = getMoods()
			If moodList.Count < len Then
				len = moodList.Count
			End If
			For i As Integer = 0 To len - 1
				Dim pos As Integer = Integer.Parse(moodList(i))
				fbml.Append(String.Format("<a class=""box"" href=""smile.aspx?smile={0}""><div class=""smiley"">{1}</div><div>{2}</div></a>",i.ToString(),moods.ElementAt(pos).Value,moods.ElementAt(pos).Key))
			Next i
			Return fbml.ToString()
		End Function
	End Class
End Namespace
